package com.xuecheng.content.feignclient;

import com.xuecheng.content.config.MultipartSupportConfig;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 远程调用媒资服务的接口
 */
// 使用fallback定义降级类是无法拿到熔断异常的
@FeignClient(value = "media-api", configuration = {MultipartSupportConfig.class})
public interface MediaServiceClient {

    @RequestMapping(value = "/media/upload/coursefile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    String upload(@RequestPart("filedata") MultipartFile filedata,
                  // 如果传递了objectName就按照我的方式存储，如果没有传就继续按照默认方式存储
                  @RequestParam(value = "objectName", required = false) String objectName) throws IOException;
}
